class FirstPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],
            keyword:'',
        };
    }


    ccheck(){
        this.freshlist()
        // let pwd = prompt('请输入密码')
        // dz_category_checkpwd(md5(pwd + Constant.SALT),res=>{
        //     if(res.data==true){
               
        //     }else{
        //         this.ccheck()
        //     }
        // })
    }


    componentDidMount() {
        $('.modal1').hide()
        let permission = $.cookie('permission'), shopname=$.cookie('shopname')
        this.setState({permission,shopname})
        this.freshlist()
       // console.log());
       // if()

         //   this.freshlist()

          


        $("#input").keydown(function (e){
            // 当 keyCode 是13时,是回车操作
           if (e.keyCode == 13){
            // 编写业务代码...
            if(this.state.showpage){
                that.freshlist()
            }
           
            // 取消之前的keydown事件
              e.preventDefault();
           }
        })
        


        // dzroom_getlist(res => {
        //     if (res.issuccess == 1) {
        //         this.setState({roomlist:res.list})
        //     }
        // })

    }
    freshlist() {
        dz_rlist({keyword:this.state.keyword},res=>{
            if (res.issuccess == 1) {
                this.setState({list:res.list})}
        })
        


    }

    quit(){
        $.cookie('token', '');
        // $.cookie('token', 'kJjOJgi0w7Nt8ozNOVbecvEPB1Wp4hLV');
         $.cookie('id', '');
         $.cookie('permission', '');
         // setalllist(res => {
         // })
         window.location.href = 'shopunknwo.html';
    }



    

    /**新建 */
    add() {
       // $('.modal1').show()
        // var name = prompt('请输入房间名称')
        // if (name != '') {
        //     aoedzroom({ name }, res => {
        //         if (res.issuccess == 1) {
        //             this.freshlist()
        //         } else {
        //             alert(res.msg)
        //         }
        //     })
        // }

       // this.setState({showchose:!0})
    }


    // 编辑
    edit(x) {
        var name = prompt('请编辑房间名称', x.name)
        if (name != ''&&name!=null&&name!=x.name) {
          //  console.log(name,'name');

          dz_projectdetail_add({ selectid: x.id, name }, res => {
                if (res.issuccess == 1) {
                 //   alert('修改成功')
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }

        // 
    }
    tosub(x) {
        window.location.href = "./dz_subcate.html?id=" + x.id + "&name=" + x.name;
    }
    // 排序
   
  


    // 删除
    del(e, cid) {
        this.setState({ delid: e, newcid: cid }, () => {
            $('#myModal').modal('toggle');
        })
    }

    confirmdel() {
        let { delid, start } = this.state
        dz_projectdetail_del(delid, res => {
            if (res.issuccess == 1) {
              //  alert('删除成功')
                $('#myModal').modal('toggle');
                this.freshlist(start)
            } else {
                $('#myModal').modal('toggle');
                alert(res.msg);
            }
        })
    }

    closemodal() {
        $('.modal1').hide()
    }

    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    confirm() {
        let{_desc,selectid} = this.state;
        if(_desc!='') {
            // alert('请输入')
            // return;
            dz_projectdetail_setdesc({desc:_desc,id:selectid},res=>{
                this.setState({showdesc:!1})
                if(res.issuccess==1){ 
                    this.freshlist()
                }else{
                    alert(res.msg)
                }
            })

        }
        // choselist.forEach(x=>{
        //     idarr.push(x.id)
        // })
      //  console.log({selectid,ids:idarr.toString(),name:fanghao});

        
    }

    toitem(id) {
       dz_recover(id,res=>{
        if(res.issuccess==1){
            this.freshlist()
        }
       })


    //   let {roomdlist,roomlist} = this.state,item=roomdlist[i],choselist=[];
    //   let idarr = item.roomids.split(',')
    //   idarr.forEach(x=>{
    //     roomlist.forEach(y=>{
    //         if(x==y.id)choselist.push(y)
    //     })
    //   })
    //   console.log(choselist,'choselistchoselist');
    //   this.setState({showchose:!0,selectid:item.id,fanghao:item.name,choselist})
    }
    copy(id){
        dz_projectd_copy(id,res=>{
            if(res.issuccess==1){
                this.freshlist()
            }
        })
      //  let 
        // dz_projectdetail_editdata(data, res => {
        //     if (res.issuccess == 1) {
        //         if (Number(id) > 0) {
        //         } else {
        //             this.setState({ id: res.id })
        //         }
        //         this.setState({ exportlist })

        //         //alert('保存成功')
        //         // if(ismoban){
        //         //     window.location.href='./dz_newroom.html?id='+res.id
        //         // }
        //     }
        // })
    }

    selectchange(e){
        this.setState({selectroomid:e.target.value}) 

    }


    addroom(){
        let {selectroomid,exportlist,totalamount} = this.state;
        if(Number(selectroomid)>0){
            dz_getprojectitemlist(selectroomid,res=>{
                if(res.issuccess==1){
                    let{room,wj,cp} =res;
                    let wjtotal = 0,cptotal=0,cptotalcount=0,wjtotalcount=0,amount=0
                    wj.forEach(x=>{
                        wjtotal= (Number(wjtotal)+(Number(x.singleprice)* Number(x.count))).toFixed(2)
                        wjtotalcount= (Number(wjtotalcount)+Number(x.count)).toFixed(2)
                    })
                    cp.forEach(x=>{
                        cptotalcount= (Number(cptotalcount)+Number(x.count)).toFixed(2)
                        cptotal= (Number(cptotal)+(Number(x.singleprice)* Number(x.count))).toFixed(2)
                    })
                    amount = (Number(wjtotal)+(Number(cptotal))).toFixed(2)
                    totalamount =(Number(totalamount)+(Number(amount))).toFixed(2)
                    let item = {room,wjtotal,cptotal,cptotalcount,wjtotalcount,amount,wj,cp}
                    console.log(item,'item');
                    exportlist.push(item)
                    console.log(exportlist,'exportlist');
                    this.setState({exportlist,totalamount})
                }
            })
        }
    }

    clickitem(i){
        let{roomlist,choselist} = this.state;
        choselist.push(roomlist[i])
        console.log(choselist,'choselist');
        this.setState({choselist})
        
    }
    choseitem(i){
        let{choselist} = this.state;
        choselist.splice(i,1)
        this.setState({choselist})
    }
    input(e){
        this.setState({fanghao:e.target.value})
    }

    tochi(e,e1){
    console.log({e,e1});
   // var b = 
    if(confirm(`确定要转入${e1==0?'签单':'下单'}池吗？`)){
        dz_changepoolroom({id:e,pool:e1==0?'QD':'XD'},res=>{
            if(res.issuccess==1){
                alert('转入成功')
            }
            //this.freshlist()
        })
    }
    
        // zroom_getlist(e,res => {
        //     if (res.issuccess == 1) {
        //         this.setState({roomlist:res.list})
        //     }
        // })
    }

    setoorder(id){
        var val = prompt('请输入排序')
        if(val!=null){
            dz_projectdetail_setorder({id,orderid:val},res=>{
                if(res.issuccess==1){
                    this.freshlist()
                }
            })
        }

    }


    render() {
        var { permission,showpage, shopname,fanghao,roomdlist, name,showchose, showdesc, choselist,_desc, subtitle,list,keyword } = this.state;
    
        return (
            
           
            <div  className="breadLinebox">


                <Modal content='确定要删除吗？' click={this.confirmdel.bind(this)} />
                

                <div className='content_wrap panel-default content_wrap'>
                    {/* <div onClick={()=>{window.location.href='./dz_cate.html'}} className='breadLine '>
                        前往分类管理
                    </div> */}
                    {/* <div className='inputs panel-body'>
                        <h3>首页管理</h3>
                    </div> */}
                    <div className="content form">
                        {/* <div style={{display:clicknew?"":"none"}} id="div"> */}

                        <div className="tabletit" >

                        <div className="shopname">{shopname}</div>
                            
                            
                            
                            <div className="content1">
                            <input id='input' placeholder="请输入业主地址" allowClear value={keyword} onChange={this.inputchange.bind(this, 'keyword')} className="input" />
                            <p className="add" onClick={()=>{this.freshlist()}}>搜索</p> 
                            {/* <p className="p2">{zje}</p> */}
                        </div>
                            {/* <p className="add" style={{'cursor':'pointer'}} onClick={()=>{window.location.href='./dz_cate.html'}}>前往分类管理</p>
                            <p className="add" style={{'cursor':'pointer'}} onClick={()=>{window.location.href='./dz_main.html'}}>客户报价</p> */} 
                            <p className="add" style={{'cursor':'pointer'}} onClick={()=>{window.location.href='./dz_main.html'}}>返回</p>
                            <div className="shopnamer">服务电话:13559580055 </div>

                        </div>
                        <table className="tab">
                            <thead>
                                <tr>
                                    {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}
                                    <th className="tconter">序号</th>
                                    <th className="tconter">排序</th>
                                    <th className="tconter">修改时间</th>
                                    <th className="tconter">业主地址</th>
                                    <th className="tconter">跟踪信息</th>
                                    <th className="cz tconter">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {
                                    list.map((x, i) => { 
                                        return (
                                            <tr key={i}>
                                                {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                <td className="tconter">{i + 1}</td>
                                                <td onClick={this.setoorder.bind(this,x.id)} style={{ 'width': '40px' }} className="tconter">{x.orderid}</td>
                                                <td className="tconter">{formatDate(new Date(x.updateDate) )}</td>
                                                
                                                <td onClick={this.edit.bind(this, x)} className="tconter">{x.name}</td>
                                                <td onClick={()=>{this.setState({showdesc:!0,_desc:x._desc,selectid:x.id})}} className="tconter lines">{x._desc}</td>
                                                
                                                <td className="operatebox">
                                                    <div className='operate' id={"ope" + x.id}>
                                                        <p className='edit' onClick={this.toitem.bind(this,x.id)}>恢复</p>
                                                      
                                                       
                                                    </div>
                                                </td>
                                            </tr>
                                        )
                                    })
                                }

                            </tbody>
                        </table>
                    </div>

                </div >


            </div >

            
        )
    }
}





ReactDOM.render(
    <div>
        {/* <LeftMenu code='0' /> */}
        <FirstPage />
    </div>
    //<Barrage/>
    , $('.container')[0]
)